// pages/account/mingxi.js
const app = getApp()
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		userInfo:{},
		flowData:{},
		page:1,
		setting:{}
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		let that = this;
		app.connect('index/setting', {}, function (res) {
			that.setData({
				setting: res
			})
		});
		app.login(function(userInfo) {
			that.setData({
				userInfo:userInfo.data
			});

			//请求流水数据
			app.connect('account/flow',{
				uid:that.data.userInfo.uid,
				openid:that.data.userInfo.openId
			},function(res){
				that.setData({
					flowData:res.data
				});
			},true);
		});
	},
	/**
	 * 触底加载更多数据
	 */
	onReachBottom: function () {
		let that = this;
		app.connect('account/flow', {
			uid: that.data.userInfo.uid,
			openid: that.data.userInfo.openId,
			page:that.data.page + 1
		}, function (res) {
			if(res.data.length == 0) {
				wx.showToast({
					title: '没有更多啦',
					icon:'none'
				})
				return false;
			}
			var data = that.data.flowData;
			that.setData({
				flowData: data.concat(res.data),
				page:that.data.page + 1
			});

		},true);
	}

})